-- Decompiled with the Synapse X Luau decompiler.

local ClientOHOH = _G.ClientOHOH;
local AudioCfg = ClientOHOH.config.audio;
local group = ClientOHOH.config.AudioGroup;
-- for k, v in pairs(AudioCfg) do
-- 	if v.group then
-- 		group[v.group] = true;
-- 	end;
-- end;
local M = ClientOHOH.class.new(script, ClientOHOH.files.AudioManager());
local ClientGlobleSounds = Instance.new("Folder", workspace);
ClientGlobleSounds.Name = "ClientGlobleSounds";
local SoundsList = nil;
local SoundService = game:GetService("SoundService");
local GroupsList = nil;
local GroupSetting = {};
local Sounds = {};

function CreateSounds(info,parent)
	local sound= Instance.new("Sound",parent)
	sound.SoundId=info.rid
	sound.Volume=info.volume
	return sound
end

function M.PreLoad(self, processBack)
	local allprocessCount = ClientOHOH:CountTable(AudioCfg) + 2;
	local v9 = coroutine.running();
	local v10 = {};
	local process=0
	if processBack then
		processBack(process, allprocessCount);
	end;
	if not SoundsList then
		SoundsList = ClientOHOH:GetPath_Loop("Sounds", SoundService);
	end;
	process=process+1
	if processBack then
		processBack(process, allprocessCount);
	end;
	if not GroupsList then
		GroupsList = ClientOHOH:GetPath_Loop("Groups", SoundService);
	end;
	process=process+1

	if processBack then
		processBack(process, allprocessCount);
	end;


	for k,v in pairs(AudioCfg) do
		if v.group and not GroupSetting[v.group] then
			GroupSetting[v.group] = ClientOHOH:GetPath_Loop(v.group, GroupsList);
		end;
		if not Sounds[k] then
			Sounds[k] = ClientOHOH:GetPath_Loop(k, SoundsList);
			--Sounds[k] = CreateSounds(v, SoundsList);
		end;
		process = process + 1;
		if processBack then
			processBack(process, allprocessCount);
		end;
	end
end;
function M.GetSound(self, id)
	assert(id, "param id is nil");
	-- assert(AudioCfg[id], "no such audio id = " .. id);
	Sounds[id] = Sounds[id] or ClientOHOH:GetPath_Loop("Sounds." .. id, SoundService);
	--Sounds[id] = Sounds[id] or CreateSounds(AudioCfg[id], SoundsList)

	return Sounds[id];
end;
function M.GetGroup(self, p6)
	assert(p6, "param group name is nil");
	assert(group[p6], "param no such group name = " .. p6);
	GroupSetting[p6] = GroupSetting[p6] or ClientOHOH:GetPath_Loop("Groups." .. p6, SoundService);
	return GroupSetting[p6];
end;
function M.SetGroupVolume(self, p8, p9)
	self:GetGroup(p8).Volume = p9;
end;
function M.GetGroupVolume(self, p11)
	return self:GetGroup(p11).Volume;
end;



function M.LoadSound(self, obj)


	local id=obj:GetAttribute("AudioId")
	assert(id, "param id  is nil");

	if Sounds[id] then
		return id
	end

    local groupId=obj:GetAttribute("Group")

	assert(groupId, "param groupId is nil" );

	local s=obj:Clone()
	s.Name=id
	s.Parent=ClientOHOH:GetPath_Loop("Sounds" , SoundService)
	Sounds[id]=s
	s.SoundGroup=self:GetGroup(groupId)
	return id
end


function M.PlayToInst(self, id, parent, playbackSpeed, loopNum)
	--print("---PlayToInst----------",id)

	if (not id) or id=="" or id==" " or id=="nil" then
		return
	end
	if id then
		return M.super.PlayToInst(self, self:GetSound(id), parent, playbackSpeed, loopNum);
	end
	
end;
function M.PlayGloble(self, id, playbackSpeed, loopNum)
	--print("---PlayGloble----------",id)
	if (not id) or id=="" or id==" " or id=="nil" then
		return
	end
	if id then
		return self:PlayToInst(id, ClientGlobleSounds, playbackSpeed, loopNum);
	end
end;
return M;
